package cn.zane.chatim.view.login;

import cn.zane.chatim.view.UIObject;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.stage.StageStyle;

/**
 * @author: zane
 * @date: 2025-09-15
 * @description: 窗体的初始化操作，可以创建一些待填充的元素
 */
public abstract class LoginInit extends UIObject {

    private static final String RESOURCE_NAME = "/fxml/login/login.fxml";
    protected ILoginEvent loginEvent;

    // 登录窗口最小化
    public Button loginMin;
    // 登录窗口退出
    public Button loginClose;
    // 登录按钮
    public Button loginButton;
    // 用户账号窗口
    public TextField userId;
    // 用户密码窗口
    public PasswordField userPassword;

    public LoginInit(ILoginEvent loginEvent) {
        this.loginEvent = loginEvent;
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(RESOURCE_NAME));
            root = fxmlLoader.load();
        }catch (Exception e){
            e.printStackTrace();
        }
        // 阴影
        DropShadow shadow = new DropShadow();
        shadow.setRadius(10);
        shadow.setColor(Color.rgb(0, 0, 0, 0.25));
        root.setEffect(shadow);

        // 场景
        Scene scene = new Scene(root);
        scene.setFill(Color.TRANSPARENT);
        setScene(scene);
        initStyle(StageStyle.TRANSPARENT);
        setResizable(false);

        this.getIcons().add(new Image(getClass().getResource("/fxml/chat/img/head/logo.png").toExternalForm()));
    }

    private void obtain(){
        loginMin = $("login_min",Button.class);
        loginClose = $("login_close",Button.class);
        loginButton = $("login_button",Button.class);
        userId = $("userId",TextField.class);
        userPassword = $("userPassword",PasswordField.class);
    }
}
